package D12_6z.反射_3;

import org.apache.commons.io.FileUtils;

import java.io.File;
import java.lang.reflect.Field;
import java.util.List;

public class Demo1 {
    public static void main(String[] args) throws Exception {
        File file = new File("src/Y2019/M12_/D12_6z/反射_3/data1.txt");
        List<String> strings = FileUtils.readLines(file);
        List<String> strings1 = FileUtils.readLines(new File("src/Y2019/M12_/D12_6z/反射_3/data2.txt"));
        for (int i = 0; i < strings.size(); i++) {
            Class<?> aClass = Class.forName(strings.get(i));
            Field id = aClass.getDeclaredField("id");
            Field name = aClass.getDeclaredField("name");
            Field age = aClass.getDeclaredField("age");
            Object o = aClass.newInstance();
            for (int i1 = 0; i1 < strings1.size(); i1++) {
                if (id.getName().equals(strings1.get(i1).split("=")[0])){
                    id.set(o,strings1.get(i1).split("=")[1]);
                }
                if (name.getName().equals(strings1.get(i1).split("=")[0])){
                    name.set(o,strings1.get(i1).split("=")[1]);
                }
                if (age.getName().equals(strings1.get(i1).split("=")[0])){
                    age.set(o,Integer.parseInt(strings1.get(i1).split("=")[1]));
                }
                if (i1==strings1.size()-1){
                    System.out.println(id.get(o)+" "+name.get(o)+" "+age.get(o));
                }
            }
        }
    }
}
